$(document).ready(function() {
	//var user_key = "z0LvnRzxZ9";
	var user_key = localStorage.user_key;
	if(!user_key)  {
		$('#username_label').html(_("username_label"));
		$('#password_label').html(_("password_label"));
		$('#login_button').val(_("login_button"));
		$('#signup_link').html(_("signup_link"));
		$('#login').show();
		$('#check').hide();
	} else {		 	
		check(user_key);		
	}
});

function check(user_key) {
	var json = {
			"device":  {"status": "out_of_session","type": "web", "uid": "vrCqWPNYJBq1"},
			"order_by": "TIMESTAMP",
			"updates_filter":{}
	};
	getApiData("check", user_key, localStorage.app_key, json, function(response) {
		var count = response.new_feeds_count;
		if(count) {
			$("#check").html(_("check_result", [count]));			
			$("#login").hide();
			$("#check").show();
		}
	});	
}


function submit_login() {
	var username = $('#username').val();
	var password = $('#password').val();
	
	apiSignin(username, password, function(resp) {
		if(resp.result == "success") {
			localStorage.user_key = resp.user_key;
			localStorage.user_id = resp.user_id;
			check(localStorage.user_key);
		} else {
			$('#message').html(resp.message);
		}
	});
	return false;
}

function signup_click() {
	alert('bananananana');
}